use serde::{Deserialize, Serialize};
use validator::Validate;
use wanmesh_common::util::deserialize_some;

#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
pub struct AddParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<WireguardConfigAddParams>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
#[serde(rename_all(serialize = "PascalCase", deserialize = "PascalCase"))]
pub struct WireguardConfigAddParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub peer: Option<WireguardPeerConfigAddParams>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
#[serde(rename_all(serialize = "PascalCase", deserialize = "PascalCase"))]
pub struct WireguardPeerConfigAddParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub endpoint: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub persistent_keepalive: Option<u32>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Default, Eq, PartialEq)]
pub struct Filter {
    pub endpoint_peer_id: Option<String>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Default, Eq, PartialEq)]
pub struct UpdateParams {
    pub config: Option<WireguardConfigUpdateParams>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Default, Eq, PartialEq)]
#[serde(rename_all(serialize = "PascalCase", deserialize = "PascalCase"))]
pub struct WireguardConfigUpdateParams {
    pub peer: Option<WireguardPeerConfigUpdateParams>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Default, Eq, PartialEq)]
#[serde(rename_all(serialize = "PascalCase", deserialize = "PascalCase"))]
pub struct WireguardPeerConfigUpdateParams {
    pub endpoint: Option<String>,
    #[serde(default, deserialize_with = "deserialize_some")]
    pub persistent_keepalive: Option<Option<u32>>,
}
